package com.beiding.workordersystem.orders.generalorder.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.beiding.workordersystem.customer.entity.CustomerEntity;
import com.beiding.workordersystem.system.entity.UserEntity;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Getter
@Setter
@TableName("bus_general_order")
public class GeneralOrder {

    private final static Map<Integer, String> statusMap = new HashMap<>();

    private final static Map<Integer, String> typeNameMap = new HashMap<>();

    static {
        statusMap.put(0, "新增");//删改
        statusMap.put(1, "退回");//删改
        statusMap.put(2, "待审核");
        statusMap.put(3, "待指派");
        statusMap.put(4, "待发布");
        statusMap.put(5, "异常");
        statusMap.put(6, "进行中");
        statusMap.put(7, "待评价");
        statusMap.put(8, "已关闭");//删
        //补
        statusMap.put(9, "审核流转");
        statusMap.put(10, "退单");

        typeNameMap.put(0, "抢单类");
        typeNameMap.put(1, "指派类");
    }

    //是否是自定义的客户
    private Boolean customerCustom;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date time;


    @TableId
    private String id;

    @TableField(exist = false)
    private String typeName;

    private String typeId;

    //是否已经完成
    private Boolean complete;

    private Double fee;

    private Double feeGot;

    private Double feeNotGot;

    //创建者id
    private String creatorId;

    //状态编码
    private Integer statusCode;

    public void setStatusCode(int code) {
        this.statusCode = code;
        this.statusName = statusMap.get(code);
    }

    //状态名称
    @TableField(exist = false)
    private String statusName;

    //提供的服务内容
    private String service;

    //0抢单类   1指派类  一旦发布就不可修改
    private Integer type;

    public void setType(Integer type) {
        this.type = type;
        this.typeName = typeNameMap.get(type);
    }

    //创建时间
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    @TableField(exist = false)
    private UserEntity creator;

    private String refuseReason;

    //负责人
    private String principalId;

    @TableField(exist = false)
    private List<OrderProcess> processes;

    //客户
    private String customerId;

    //客户实体
    @TableField(exist = false)
    private CustomerEntity customer;

    //当前激活的工序
    @TableField(exist = false)
    private OrderProcess activatedProcess;

}
